<?php

namespace Models;
use Phalcon\Mvc\Model\Validator\Uniqueness as Uniqueness;
class Role extends BaseModel
{
    public function initialize()
    {
        $this->hasMany("role_id", "Models\Record", "role_id", array('alias' => 'Record'));
    }

    public function validation()
    {
        $this->validate(new Uniqueness(array(
            'field' => 'title',
            'message' => '角色名已存在',
        )));
        if ($this->validationHasFailed() == true) {
            return false;
        }
    }

    public function notSave()
    {
        //Obtain the flash service from the DI container
        $flash = $this->getDI()->getFlash();

        //Show validation messages
        foreach ($this->getMessages() as $message) {
            $flash->error($message);
        }
    }

}